package com.ruoyi.carrepair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carrepair.domain.QxPeijian;
import com.ruoyi.carrepair.service.IQxPeijianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/carrepair/peijian")
public class QxPeijianController extends BaseController
{
    @Autowired
    private IQxPeijianService qxPeijianService;

    /**
     * 查询配件管理列表
     */
    //@PreAuthorize("@ss.hasPermi('carrepair:peijian:list')")
    @GetMapping("/list")
    public TableDataInfo list(QxPeijian qxPeijian)
    {
        startPage();
        List<QxPeijian> list = qxPeijianService.selectQxPeijianList(qxPeijian);
        return getDataTable(list);
    }

    /**
     * 导出配件管理列表
     */
    @PreAuthorize("@ss.hasPermi('carrepair:peijian:export')")
    @Log(title = "配件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QxPeijian qxPeijian)
    {
        List<QxPeijian> list = qxPeijianService.selectQxPeijianList(qxPeijian);
        ExcelUtil<QxPeijian> util = new ExcelUtil<QxPeijian>(QxPeijian.class);
        util.exportExcel(response, list, "配件管理数据");
    }

    /**
     * 获取配件管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('carrepair:peijian:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(qxPeijianService.selectQxPeijianById(id));
    }

    /**
     * 新增配件管理
     */
    @PreAuthorize("@ss.hasPermi('carrepair:peijian:add')")
    @Log(title = "配件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QxPeijian qxPeijian)
    {
        return toAjax(qxPeijianService.insertQxPeijian(qxPeijian));
    }

    /**
     * 修改配件管理
     */
    @PreAuthorize("@ss.hasPermi('carrepair:peijian:edit')")
    @Log(title = "配件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QxPeijian qxPeijian)
    {
        return toAjax(qxPeijianService.updateQxPeijian(qxPeijian));
    }

    /**
     * 删除配件管理
     */
    @PreAuthorize("@ss.hasPermi('carrepair:peijian:remove')")
    @Log(title = "配件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(qxPeijianService.deleteQxPeijianByIds(ids));
    }
}
